package mysql

import "gorm.io/gorm"

type User struct {
	gorm.Model
	Phone         string `gorm:"type:varchar(20);not null"`
	Password      string `gorm:"type:char(32);not null"`
	NickName      string `gorm:"type:varchar(30);not null"`
	AvatarLink    string `gorm:"type:varchar(500)"`
	AccountStatus int    `gorm:"type:int(11);default:0;not null"`
	FollowNum     int    `gorm:"type:int(11);default:0;not null"`
	FansNum       int    `gorm:"type:int(11);default:0;not null"`
}

func (u *User) FindUserByPhone(db *gorm.DB, phone string) error {
	return db.Debug().Where("phone=?", phone).Find(u).Error
}

func (u *User) UserAdd(db *gorm.DB) error {
	return db.Debug().Create(u).Error
}

func (u *User) ForgetPassword(db *gorm.DB) error {
	return db.Debug().Updates(u).Error
}

func (u *User) UpdateNickName(db *gorm.DB) error {
	return db.Debug().Updates(u).Error
}

func (u *User) FirstUserByUserId(db *gorm.DB, UserId int64) error {
	return db.Debug().Where("id", UserId).Find(u).Error
}
